#ifndef KBDEV_H
#define KBDEV_H

//=======================================================================//
//= Include files                                                      =//
//=======================================================================//
#include <linux/input.h>

//=======================================================================//
//= Macro definition                                                   =//
//=======================================================================//
#define EVKEYB_NAME "/dev/input/event0"

// 按键值定义（根据实际应用需求定义）
// #define KBDEV_KEY_UP        0x013D
// #define KBDEV_KEY_DOWN      0x013E
// #define KBDEV_KEY_ENTER     0x013B
// #define KBDEV_KEY_ESC       0x011B
// #define KBDEV_KEY_INVALID   0x0000

//=======================================================================//
//= Type definition                                                    =//
//=======================================================================//
// 按键事件类型
typedef enum {
    KBDEV_EVENT_RELEASE = 0,    // 按键释放
    KBDEV_EVENT_PRESS = 1,      // 按键按下
    KBDEV_EVENT_REPEAT = 2      // 按键重复
} KBDEV_EVENT_TYPE;

// 按键信息结构体
typedef struct {
    unsigned int    uiKeyValue;     // 按键值
    int             iEventType;     // 按键事件类型
} KBDEV_KEY_INFO;

//=======================================================================//
//= Function declaration                                               =//
//=======================================================================//

/*****************************************************************************/
/** Function Name:  KBDEV_Initialize                                        **/
/** Purpose:        Initialize keyboard device                              **/
/** Parameters:     None                                                    **/
/** Return:         0 on success, -1 on failure                             **/
/*****************************************************************************/
int KBDEV_Initialize(void);

/*****************************************************************************/
/** Function Name:  KBDEV_ReadKey                                           **/
/** Purpose:        Read key event from keyboard device                     **/
/** Parameters:                                                             **/
/** @ pstKeyInfo[out]: Pointer to store key information                     **/
/** Return:         1 if key event available, 0 if no event, -1 on error    **/
/*****************************************************************************/
int KBDEV_ReadKey(KBDEV_KEY_INFO* pstKeyInfo);

/*****************************************************************************/
/** Function Name:  KBDEV_PollEvent                                        **/
/** Purpose:        Check if there is key event available                   **/
/** Parameters:                                                             **/
/** @ iTimeoutMS[in]: Timeout in milliseconds (0 = non-blocking)            **/
/** Return:         1 if event available, 0 if timeout, -1 on error         **/
/*****************************************************************************/
int KBDEV_PollEvent(int iTimeoutMS);

/*****************************************************************************/
/** Function Name:  KBDEV_TranslateKeyCode                                 **/
/** Purpose:        Translate raw key code to application key value         **/
/** Parameters:                                                             **/
/** @ iKeyCode[in]: Raw key code from input event                           **/
/** @ iEventType[in]: Key event type                                        **/
/** Return:         Translated key value                                    **/
/*****************************************************************************/
unsigned int KBDEV_TranslateKeyCode(int iKeyCode, int iEventType);

/*****************************************************************************/
/** Function Name:  KBDEV_Close                                             **/
/** Purpose:        Close keyboard device                                   **/
/** Parameters:     None                                                    **/
/** Return:         None                                                    **/
/*****************************************************************************/
void KBDEV_Close(void);

#endif /* KBDEV_H */